Drupal 11: Controlling LED Lights Using A REST Service
Following on from my article looking at the Pimoroni Plasma 2350 W I decided to do something interesting with the Wifi interface that would connect to a Drupal site.
The firmware of the Plasma 2350 W from Pimoroni comes with an example that connects to a free API to update the colour randomly. Once I saw this in action I realised that it shouldn't be too hard to convert that to pull the data from a Drupal REST service instead.
It is quite easy to create RESTful services in Drupal; it just needs a single class. All I would need to do is create a form to control the colour that is selected in the REST service.
In this article we will look at creating a Drupal module containing a RESTful interface, which we will connect to with the Plasma 2350 W to update the colour of the lights.
Setting Up The Form
In order to allow the colour of the LED lights to be set I needed to create a form that would do just that.
To save the colour to the system we will use the state service, which is a handy little key/value service that allows us to write simple values to the database. This service is a good way of storing values that aren't part of the Drupal configuration system. Ideally, you want values that can be easily recreated by the system if they don't already exist. The colour setting is therefore an ideal candidate for the state service.
Setting the form up with this service injected is simple enough, but we can also simplify the form integration by abstracting away the get and set methods for the state itself.
This is what the basic structure of the form class looks like.
You're reading a website, but the text feels cramped. Lines are too close together, making it hard to track from one line to the next. Words blur together. You try increasing your browser's font size, but that only makes part of the problem worse - now the text is bigger but still squished together.
If you could just add a little more space between lines, between words, between letters... you'd be able to read comfortably. But when you try using a browser extension to adjust spacing, the layout breaks. Text gets cut off. Paragraphs overlap. Buttons disappear.
This week, we published an article about how we controlled 1,200 screens in real time with Symfony during SymfonyCon Amsterdam 2025. We also celebrated a new SymfonyCasts course on building Symfony bundles. Finally, we shared a blog post detailing 20 years…
Imagine navigating a website with only your keyboard. You hit Tab to move through interactive elements. First tab: logo link. Second tab: search box. Third tab: first navigation link. Fourth, fifth, sixth tabs: more navigation links. Seventh tab: social media icons. Eighth tab: language selector. Finally, after nine or ten tab presses, you reach the actual content of the page.
Now imagine doing this on every single page you visit. Every. Single. Time.
In 2025, we're celebrating 20 years of Symfony. Over these years, thousands of people have contributed code to Symfony. Some folks fixed a small typo in a comment, while others added more than 100,000 lines of code. All contributions are welcome and essential…
Symfony bundles are one of the framework's most powerful ideas: reusable, shareable building blocks that let you package features once and use them everywhere. But building a great bundle is very different from building an application. It's an area that many…